import actionTypes from "./actionTypes"
import service from '../../service'
export function LoadGoodsAction(payload){
  return{
    type:actionTypes.LOAD_GOODS_LIST,
    payload:payload,
  }
}
export function LoadGoodsActionAsync(payload){
  return dispatch=>{
    return service.loadGoodsList(payload).then((res)=>{
      dispatch(LoadGoodsAction(res.data))
    })
  }
}
export function addGoodsAction(payload){
  return{
    type:actionTypes.ADD_GOODS,
    payload:payload,
  }
}
export function addGoodsActionAsync(payload){
  return dispatch=>{
    return service.addGoods(payload).then((res)=>{
      dispatch(addGoodsAction(res.data))
    })
  }
}
export function deleteGoodsActionAsync(payload){
  return dispatch=>{
    return service.deleteGoods(payload)
  }
}
export function updateGoodsActionAsync(payload){
  return dispatch=>{
    return service.updateGoods(payload)
  }
}
export function searchGoodsActionAsync(payload){
  return dispatch=>{
    return service.searchGoods(payload).then((res)=>{
      dispatch(LoadGoodsAction(res.data))
    })
  }
}